package cn.stu.common.utils;

import cn.hutool.core.util.ReflectUtil;
import org.springframework.cglib.beans.BeanCopier;

/**
 * 实用程序
 *
 * @author 郑志豪
 * @date 2023/09/18
 */
public class BeanUtils {
    public static <T> T copier(Object source, Class<T> tClass, String... ignoreProperties) {
        T target = ReflectUtil.newInstanceIfPossible(tClass);
        BeanCopier copier = BeanCopier.create(source.getClass(), tClass, false);
        copier.copy(source, target, null);
        return target;
    }

    public static <T, E> E copier(T t, E e) {
        if (t == null) {
            return null;
        }
        org.springframework.beans.BeanUtils.copyProperties(t, e);
        if (e instanceof Format) {
            ((Format) e).format();
        }
        return e;
    }
}
